/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.chart.bubble;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.SwingUtilities;

import demo.DemoPane;
import demo.chart.Portlet;
import demo.chart.PortletPanel;

public class BubbleChartDemo extends DemoPane implements PortletPanel {
	
	private boolean isFullScreen = false;
	private List chartList = new ArrayList();
	private GridLayout layout;
	private WeekBubbleChart weekBubbleChart;
	private GroupChart groupChart;
	private SimpleBubbleChart simpleBubbleChart;
	private HashBubbleChart hashBubbleChart;
	private QuadrantChart quadrantChart;
	private CountryAreaChart countryAreaChart;

	public BubbleChartDemo() {
		layout = new GridLayout(2, 3, 5, 5);
		weekBubbleChart = new WeekBubbleChart();
		groupChart = new GroupChart();
		simpleBubbleChart = new SimpleBubbleChart();
		hashBubbleChart = new HashBubbleChart();
		quadrantChart = new QuadrantChart();
		countryAreaChart = new CountryAreaChart();
		chartList.add(weekBubbleChart);
		chartList.add(groupChart);
		chartList.add(simpleBubbleChart);
		chartList.add(hashBubbleChart);
		chartList.add(quadrantChart);
		chartList.add(countryAreaChart);
		initialize();
		
		Thread t = new Thread(new Runnable() {
			public void run() {
				try {
					while (true) {
						if (isShowing()) {
							SwingUtilities.invokeAndWait(new Runnable() {
								public void run() {
									int size = chartList.size();
									for (int i = 0; i < size; i++) {
										((Portlet) chartList.get(i)).run();
									}
								}
							});
						}
						Thread.sleep(200);
					}
				} catch (Exception e) {
				}
			}
		});
		t.start();
	}

	public void initialize() {
		this.setLayout(layout);
		int size = chartList.size();
		for (int i = 0; i < size; i++) {
			this.add((Portlet) chartList.get(i));
		}
	}

	public void fullScreen(Portlet portlet) {
		this.removeAll();
		isFullScreen = !isFullScreen;
		if (isFullScreen) {
			this.setLayout(new BorderLayout());
			this.add(portlet, BorderLayout.CENTER);
		} else {
			initialize();
		}
		portlet.getChart().reset();
		this.repaint();
		this.revalidate();
	}
}